#include<sys/types.h>//对于此程序而言此头文件types.h用不到
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
int main() {
 int pid = 0;
 // fork a worker process
 if (pid = fork()) {
 // wait for completion of the child process
 int status; 
 waitpid(pid, &status, 0);
 }
 else {
 // open input and output files
 int fd_in = open("in.txt", O_RDONLY);
 int fd_out = open("out.txt", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 if (fd_in > 0 && fd_out > 0) {
 // redirect STDIN/STDOUT for this process
 dup2(fd_in, 0);
 dup2(fd_out, 1); 
 // call shell command
 system("sort");
 close(fd_in);
 close(fd_out);
 }
 else {
 }
 }
 return 0;
}
